package com.itheima.tlias84.service.impl;

import com.itheima.tlias84.mapper.DataStatisticsMapper;
import com.itheima.tlias84.service.DataStatisticsService;
import com.itheima.tlias84.utils.ResultUtil;
import com.itheima.tlias84.vo.Gender;
import com.itheima.tlias84.vo.Job;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.logging.stdout.StdOutImpl;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Service
public class DataStatisticsServiceImpl implements DataStatisticsService {

    @Resource
    DataStatisticsMapper dataStatisticsMapper;

    @Override
    public List<Gender> selectByGender() {
        List<Gender> genders = dataStatisticsMapper.selectByGender();
        for (Gender gender : genders) {
            if (gender.getName().equals("1")) {
                gender.setName("男");
            } else {
                gender.setName("女");
            }
        }
        return genders;
    }

    @Override
    public ResultUtil selectByJob() {
        List<Gender> genders = dataStatisticsMapper.selectByJob();
            Job job = new Job();
        ArrayList<Object> jobList = new ArrayList<>();
        ArrayList<Object> dataList = new ArrayList<>();
        for (Gender gender : genders) {
            if (gender.getName().equals("1")) {
                jobList.add("班主任");
                if (Objects.isNull(gender.getValue())) {
                    dataList.add("0");
                } else {
                    dataList.add(gender.getValue());
                }

            } else if (gender.getName().equals("2")) {
                jobList.add("讲师");
                if (Objects.isNull(gender.getValue())) {
                    dataList.add("0");
                } else {
                    dataList.add(gender.getValue());
                }
            } else if (gender.getName().equals("3")) {
                jobList.add("学工");
                if (Objects.isNull(gender.getValue())) {
                    dataList.add("0");
                } else {
                    dataList.add(gender.getValue());
                }
            } else if (gender.getName().equals("4")) {
                jobList.add("校验");
                if (Objects.isNull(gender.getValue())) {
                    dataList.add("0");
                } else {
                    dataList.add(gender.getValue());
                }
            } else if (gender.getName().equals("5")) {
                jobList.add("咨询师");
                if (Objects.isNull(gender.getValue())) {
                    dataList.add("0");
                } else {
                    dataList.add(gender.getValue());
                }
            } else {
                jobList.add("其他");
                if (Objects.isNull(gender.getValue())) {
                    dataList.add("0");
                } else {
                    dataList.add(gender.getValue());
                }

            }
        }
        job.setJobList(jobList);
        job.setDataList(dataList);
            return ResultUtil.success(job);
    }
}